/*
** serv_monitor.c for zappy in /home/druart_p/Work/projet/zappy/zappy-2015-2014s-renard_g/serv-src
**
** Made by pierrick druart
** Login   <druart_p@epitech.net>
**
** Started on  Mon Jul  9 15:00:00 2012 pierrick druart
** Last update Fri Jul 13 14:35:30 2012 maximilien addari
*/

#include		<string.h>
#include		<stdlib.h>

#include		"server.h"

static t_serv_monitor	ptr_serv_monitor[]=
  {
    {"ppo", &serv_ppo},
    {"pin", &serv_pin},
    {"bct", &serv_bct},
    {"pnw", &serv_pnw},
    {"pdi", &serv_pdi},
    {"pfk", &serv_pfk},
    {"pic", &serv_pic},
    {NULL, 0}
  };

void			serv_monitor(char *cmd, t_client *client, \
				t_game *game, t_client *graphic)
{
  int			i;

  i = 0;
  if (graphic != NULL)
    {
      while (ptr_serv_monitor[i].cmd)
	{
	  if (!strncmp(cmd, ptr_serv_monitor[i].cmd, \
		       strlen(ptr_serv_monitor[i].cmd)))
	    ptr_serv_monitor[i].cmdfct(client, game, graphic);
	  i++;
	}
    }
}

void			serv_pdi(t_client *client, t_game *game, t_client *graphic)
{
  (void)game;
  graphic->send->concat(graphic->send, "pdi ");
  graphic->send->concat_value(graphic->send, client->sock);
  graphic->send->concat(graphic->send, "\n");
}

void			serv_pfk(t_client *client, t_game *game, t_client *graphic)
{
  (void)game;
  graphic->send->concat(graphic->send, "pfk ");
  graphic->send->concat_value(graphic->send, client->sock);
  graphic->send->concat(graphic->send, "\n");
}

void			serv_pic(t_client *client, t_game *game, t_client *graphic)
{
  (void)game;
  graphic->send->concat(graphic->send, "pic ");
  graphic->send->concat_value(graphic->send, client->gamer->coord.x);
  graphic->send->concat(graphic->send, " ");
  graphic->send->concat_value(graphic->send, client->gamer->coord.y);
  graphic->send->concat(graphic->send, " ");
  graphic->send->concat_value(graphic->send, client->gamer->level);
  graphic->send->concat(graphic->send, " ");
  graphic->send->concat_value(graphic->send, client->sock);
  graphic->send->concat(graphic->send, "\n");
}
